package com.xkdx.guangguang.fragment.comment;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.ShopCommentary;

public class ShopMoreCommentModule extends AbsModule {
	List<ShopCommentary> shopCommentList;
	String shopCommentNum = "0";

	@Override
	public void parseData() throws Exception {

		try {
			backJson = (JSONArray) result;

			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getCommentListByShop")) {
					shopCommentList = parseAllCommentInfo(jsonObj
							.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			// to do define a exception include all parseException
			throw e;
		}

	}

	// 解析评论详情内容
	private List<ShopCommentary> parseAllCommentInfo(JSONObject person)
			throws Exception {
		List<ShopCommentary> list = new ArrayList<ShopCommentary>();
		try {
			JSONObject stut = (JSONObject) person.get("Result");

			if (stut.has("DetailInfo")) {
				JSONObject detail = stut.getJSONObject("DetailInfo");
				shopCommentNum = detail.getString("DataCount");

			}
			if (stut.has("ListInfo")) {
				JSONArray ListInfo = (JSONArray) stut.getJSONArray("ListInfo");
				for (int i = 0; i < ListInfo.length(); i++) {
					JSONObject jsonObj = ((JSONObject) ListInfo.opt(i));
					ShopCommentary commentinfo = new ShopCommentary();
					commentinfo.setCommentContent(jsonObj
							.getString("CommentContent"));
					commentinfo.setNickName(jsonObj.getString("NickName"));
					commentinfo.setCreateTime(jsonObj.getString("CreateTime"));
					commentinfo.setPictrueUrl(jsonObj.getString("PictureUrl"));
					commentinfo
							.setUserAvatars(jsonObj.getString("UserAvatars"));
					list.add(commentinfo);
				}
			}

		} catch (Exception e) {
			throw e;
		}

		return list;
	}
}
